package com.jcl.recruit.resume.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.resume.mapper.ResumeWorkMapper;
import com.jcl.recruit.resume.model.ResumeWork;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ResumeWorkLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/10/31 11:19
 * @Version 1.0
 **/
@Component
public class ResumeWorkLogic implements ResumeWorkMapper {

    @Autowired
    private ResumeWorkMapper resumeWorkMapper;

    public Map<Integer, List<ResumeWork>> findListByResumeMap(String corpCode, List<Integer> resumeIds) {

        Map<Integer, List<ResumeWork>> dataMap = new HashMap<>();
        List<ResumeWork> list = resumeWorkMapper.findListByResumeIds(corpCode, resumeIds);
        if (CollectionUtils.isNotEmpty(list)) {
            for (ResumeWork entity : list) {
                List<ResumeWork> entityList = dataMap.get(entity.getResumeId());
                if (null == entityList) {
                    entityList = new ArrayList<>();
                    dataMap.put(entity.getResumeId(), entityList);
                }
                entityList.add(entity);
            }
        }
        return dataMap;
    }

    @Override
    public List<ResumeWork> findListByResumeIds(String corpCode, List<Integer> resumeIds) {
        return resumeWorkMapper.findListByResumeIds(corpCode, resumeIds);
    }

    @Override
    public List<ResumeWork> findListByResumeId(String corpCode, Integer resumeId) {
        return resumeWorkMapper.findListByResumeId(corpCode, resumeId);
    }

    @Override
    public List<Map<String, Object>> findObjListByResumeId(String corpCode, Integer resumeId) {
        return resumeWorkMapper.findObjListByResumeId(corpCode, resumeId);
    }

    @Override
    public int isExitEntity(ResumeWork entity) {
        return resumeWorkMapper.isExitEntity(entity);
    }

    @Override
    public int batchInsert(List<ResumeWork> list) {
        return resumeWorkMapper.batchInsert(list);
    }

    @Override
    public int insert(ResumeWork entity) {
        return resumeWorkMapper.insert(entity);
    }

    @Override
    public int updateByPrimaryKey(ResumeWork entity) {
        return resumeWorkMapper.updateByPrimaryKey(entity);
    }

    @Override
    public int deleteById(Integer id) {
        return resumeWorkMapper.deleteById(id);
    }

    @Override
    public int batchDeleteByResumeIds(String corpCode, List<Integer> resumeIds) {
        return resumeWorkMapper.batchDeleteByResumeIds(corpCode, resumeIds);
    }
}
